<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./OL_SDK/include-openlayers-local.js"></script>
    <script src="./libs/gaode.js"></script>
</head>

<body>
    <div id="map">
    </div>
    <script>
        var map = new ol.Map({
            target: "map",
            layers: [gaode],
            view: new ol.View({
                projection: 'EPSG:4326',
                center: [114.30, 30.50],
                zoom: 4
            })
        })
        let source = new ol.source.Vector({})
        let layer = new ol.layer.Vector({
            source
        })
        map.addLayer(layer)
        /* 2、创建画笔  */
        let draw = new ol.interaction.Draw({
            // 在哪个(画布)数据源上绘制
            source: source,
            // 绘制的类型
            type: 'Polygon' // 'Circle' 'LineString' 'Point' 'Polygon'
        })
        /* 3、将画笔添加到地图 */
        // console.log(map)
        map.addInteraction(draw);
        /* 监听画笔 */
        draw.on("drawend", evt => {
            var geom = evt.feature.getGeometry()
            console.log(geom)
            const coordinates = geom.getCoordinates()
            console.log(coordinates,'coordinates')// 三维数组
            const area = geom.getArea()
            console.log(area)// 面积
        })
        /*
        type: Point,LineString,Circle,Polygon
        Square正方形(Circle的一种) Box矩形(LineString的一种)
         */
    </script>
</body>

</html>